package com.robaone.gwt.hierarcialdb.client.state;

import java.util.HashMap;
import java.util.Vector;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlowPanel;
import com.robaone.gwt.hierarcialdb.client.Hierarcialdbadmin;
import com.robaone.gwt.hierarcialdb.client.ui.admin.AdminUi;
import com.robaone.gwt.hierarcialdb.client.ui.admin.FolderUi;

public class AdminState {

	public static void go() {
		AdminUi admin = new AdminUi();
		Hierarcialdbadmin.getLayout().setContent(admin);
	}

	public static void showFolder(String id) {
		AdminUi admin = AdminState.getAdminUi();
		admin.showFolderbyId(id);
		
	}

	private static AdminUi getAdminUi() {
		FlowPanel content = Hierarcialdbadmin.getLayout().getContent();
		AdminUi admin = null;
		for(int i = 0; i < content.getWidgetCount();i++){
			if(content.getWidget(i) instanceof AdminUi){
				admin = (AdminUi)content.getWidget(i);
				break;
			}
		}
		if(admin == null){
			admin = new AdminUi();
			Hierarcialdbadmin.getLayout().setContent(admin);
		}
		return admin;
	}

	public static void showFileContents(String id) {
		AdminUi admin = AdminState.getAdminUi();
		admin.showFileContents(id);
		
	}
}
